package com.kb.order.controller;

import com.kb.order.pojo.Food;
import com.kb.order.pojo.ShopInfo;
import com.kb.order.service.IFoodService;
import com.kb.order.service.IShopInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("find")
@ResponseBody
public class FindFoodController {
    @Autowired
    IShopInfoService infoService;
    @Autowired
    IFoodService foodService;
    /**
     * 根据省市区地址查找店铺
     * @param province
     * @param city
     * @param county
     * @return
     */
    @GetMapping("findshop")
    public List<ShopInfo> findshop(String province, String city, String county){
        List<ShopInfo> list = new ArrayList<>();
        System.out.println(province+city+county);
        ShopInfo shop = new ShopInfo();
        shop.setProvince(province);
        shop.setCity(city);
        System.out.println(county);
        if(county!=null && county!=""){
            shop.setDistrict(county);
        }
        list = infoService.selectshop(shop);
        return list;
    }

    /**
     * 查找美食
     * @param province
     * @param city
     * @param county
     * @return
     */
    @GetMapping("findfoods")
    public List<Food> findfoods(String province, String city, String county){
        List<Long> id = new ArrayList<>();
        List<ShopInfo> shoplist = new ArrayList<>();
        System.out.println(province+city+county);
        ShopInfo shop = new ShopInfo();
        shop.setProvince(province);
        shop.setCity(city);
        if(county!=null && county!=""){
            shop.setDistrict(county);
        }

        shoplist= infoService.selectshop(shop);
        for(ShopInfo shops:shoplist){
            id.add(shops.getId());
        }
        System.out.println(id);

        List<Food> list = new ArrayList<>();
        list = foodService.selectbyshopid(id);
        for (Food food:list) {
            System.out.println(food);
        }
        return list;
    }
}
